var User=require('../models/userModel.js');
var code=require('../txtCode/code.js');
module.exports={
	GetHtml:function(req,res){
		if(req.session){
			res.render('listAssistant',function(err,html){
				res.send(html);
			});
		}//if
	},//GetHtml
	ListAssistant:function(req,res){
		if(req.session){
			User
			.find({role:'assistant'})
			.sort({mobile:1})
			.limit(10)
			.then(
				function(result){
					// console.log(result);
					res.send({code:code.success,data:result});
					}
				,function(err){
					if(err) console.log(err);
					res.send({code:code.findFail});
			});
		}//if
	},//ListAssistant
	PageQuantity:function(req,res){
		if(req.session){
			// console.log('?');
			User
			.find({role:'assistant'})
			.sort({mobile:1})
			.count(function(err,count){
				if(err) console.log(err);
				console.log(count);
				var pageQuantity=Math.ceil(count/10);
				res.send({
					code:code.success,
					data:{'pageQuantity':pageQuantity}});
			});
			// console.log(number);
			// console.log(User
			// .find({role:'assistant'})
			// .sort({mobile:1})
			// .count());
			// res.send({
			// 	code:[8000,'something is wrong'],
			// 	data:{pageQuantity:1000}
			// });
		}//if
	},//PageNumber
	ShowPage:function(req,res){
		if(req.session){
			var PAGE_SIZE=10;
			console.log(req.body);
			var pageNumber=(parseInt(req.body.pageNumber)-1)*PAGE_SIZE;
			User
			.find({role:'assistant'})
			.sort()
			.skip(pageNumber)
			.limit(10)
			.then(function(result){
				console.log(result);
				res.send({
					code:[1000,'success'],
					data:result
				});
			});

		}//if
	}//ShowPage
}